﻿using System;
using System.IO;
using MG_POS_PC.Model;
using MG_POS_PC.Util;
using System.Data.SqlClient;

namespace MG_POS_PC.DAL
{
    public class SocketResponseDao
    {
        private string filename = System.Environment.CurrentDirectory + "\\" + FileName.xmlDBs;

        public void insert(SocketResponse sr)
        {
            //DBHelper.initDB(filename);
            //SqlConnection con = DBHelper.conn;
            //con.Open();
            //SqlCommand cmd = con.CreateCommand();


            //Item item;
            //string createDateTime = sr.CreateDateTime;
            //string fromIpAddress = sr.FromIpAddress;
            //object responseResult = sr.ResponseResult;
            //bool hasError = sr.HasError;
            //string errorMsg = sr.ErrorMsg;

            //string result = (string)responseResult;
            //string[] resultArr = result.Split(new Char[] { '|' });

            //string package = resultArr[0];
            ////writeLog(package);
            //for (int i = 1; i < resultArr.Length;i++ )
            //{
            //    item = new Item();
            //    int length = resultArr[i].Length;
            //    string newStr =resultArr[i].Substring(1,length-2);
            //    string[] itemDetail = newStr.Split(new Char[] { ',' });
            //    item.CreateDateTime = createDateTime;
            //    item.FromIpAddress = fromIpAddress;
            //    item.HasError = hasError;
            //    item.ErrorMsg = errorMsg;
            //    item.ReportType = package;
            //    item.ReportId = itemDetail[0];
            //    int len = itemDetail[1].Length;
            //    item.ReportName = itemDetail[1].Substring(1, len-2);
            //    item.ReportCnt = itemDetail[2];
            //    item.ReportPrice = itemDetail[3];

            //    cmd.CommandText = "INSERT INTO TmpItems VALUES('" + item.FromIpAddress + "','" + item.CreateDateTime + "','0','" + item.ErrorMsg + "','" + item.ReportType + "','" + item.ReportId + "','" + item.ReportName + "','" + item.ReportCnt + "','" + item.ReportPrice + "')";
            //    int a = cmd.ExecuteNonQuery();
            //    writeLog(a + "--a");
            //}
            //con.Close();
        }
        public static void writeLog(string mess)
        {
            FileStream fs = new FileStream(@"c:/mcWindowsService.txt", FileMode.OpenOrCreate, FileAccess.Write);
            StreamWriter m_streamWriter = new StreamWriter(fs);
            m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
            m_streamWriter.WriteLine(" -->" + mess);
            m_streamWriter.Flush();
            m_streamWriter.Close();
            fs.Close();
        }

    }
}
